{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e8b27860",
   "metadata": {},
   "source": [
    "# What\n",
    "生存任务，只支持List模式\n",
    "\n",
    "1. List模式，需要输入`train`, `valid`两个测试集对应的训练文件，每行一个样本。`labels.txt`是可选参数，里面每个类别一行。`data_pattern`一个通用的目录，与train、val中的第一列进行拼接。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "02dd7e75",
   "metadata": {},
   "source": [
    "### 支持的模型名称\n",
    "\n",
    "模型名称替换代码中的 `model_name`变量的值。\n",
    "\n",
    "| **模型系列** | **模型名称**                                                 |\n",
    "| ------------ | ------------------------------------------------------------ |\n",
    "| ResNet       | resnet10, resnet18, resnet34, resnet50, resnet101, resnet152, resnet200 |\n",
    "| DenseNet     | DenseNet121, DenseNet169, DenseNet201, DenseNet264           |\n",
    "| ShuffleNet   | ShuffleNet |\n",
    "| Transformer     | ViT, SimpleViT         |\n",
    "| OnekeyAI | UNetClassification |             "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0e861016",
   "metadata": {},
   "source": [
    "### List模式\n",
    "\n",
    "在Onekey中List模式一般是采用labelme标注出来的结果，如果要使用自己的数据应用List模式，需要根据自己的实际情况对数据进行处理。\n",
    "\n",
    "* `train.txt`，训练数据列表，中间用\\t（Tab水平制表符）进行分割。\n",
    "* `val.txt`，验证数据列表，中间用\\t（Tab水平制表符）进行分割。\n",
    "* `labels.txt`，label的集合，表明训练数据多少标签。\n",
    "* `data_pattern`参数，所有数据存在的目录的公共前缀，如果`train.txt`,`val.txt`文件里面存放的是绝对路径，`data_pattern`设置为None即可。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ff41912c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<iframe src=\"//player.bilibili.com/player.html?isOutside=true&aid=114861803642855&bvid=BV19xutzrE1P&cid=31079008859&p=1\" scrolling=\"no\" border=\"0\" frameborder=\"no\" framespacing=\"0\" allowfullscreen=\"true\" width=\"980\" height=\"551\"></iframe>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 获得视频教程\n",
    "from onekey_algo.custom.Manager import onekey_show\n",
    "onekey_show('3DCNN+Cox', force_show=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7050436a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from onekey_algo.survival3d.run_survival3d import main as sur_main\n",
    "from collections import namedtuple\n",
    "\n",
    "# 模型参数\n",
    "roi_size = [64, 64, 48]\n",
    "vit_settings = {\n",
    "        'image_size': roi_size[0],  # image size\n",
    "        'frames': roi_size[-1],  # number of frames\n",
    "        'image_patch_size': 16,  # image patch size\n",
    "        'frame_patch_size': 2,  # frame patch size\n",
    "        'dim': 1024,\n",
    "        'depth': 6,\n",
    "        'heads': 8,\n",
    "        'mlp_dim': 2048,\n",
    "        'dropout': 0.1,\n",
    "        'emb_dropout': 0.1}\n",
    "# 设置参数\n",
    "train = r'C:\\Users\\onekey\\Desktop\\demo\\train25d-RND-1.txt'\n",
    "val = r'C:\\Users\\onekey\\Desktop\\demo\\val25d-RND-1.txt'\n",
    "data_pattern = r'C:\\Users\\onekey\\Desktop\\demo\\20250627\\Demodata/images/'\n",
    "model_root = r'C:\\Users\\onekey\\Desktop\\demo\\sur3d'\n",
    "\n",
    "params = dict(train=train,\n",
    "              val=val,\n",
    "              data_pattern=data_pattern,\n",
    "              j=0,\n",
    "              max2use=None,\n",
    "              normalize_method='imagenet',\n",
    "              model_name='resnet50',\n",
    "              gpus=[0],\n",
    "              roi_size=roi_size,\n",
    "              batch_size=4,\n",
    "              epochs=1,\n",
    "              init_lr=0.001,\n",
    "              optimizer='adam',\n",
    "              retrain=None,\n",
    "              model_root=model_root,\n",
    "              val_interval=1,\n",
    "              iters_verbose=10,\n",
    "              save_per_epoch=False,\n",
    "              model_config={'groups': 1, 'blocks_args': 'efficientnet-b4'},\n",
    "              vit_settings=vit_settings,\n",
    "              pretrained=True)\n",
    "# 训练模型\n",
    "Args = namedtuple(\"Args\", params)\n",
    "sur_main(Args(**params))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ce1f8dc1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
